package QC.MessageBox.enums;

import io.vertx.core.json.JsonObject;

/**
 * Created by Andaren on 2017/5/26.
 * Used for: 消息发送结果
 */
public enum SendResult {
    SUCCESS(1, "发送完成"),
    FAILED_TOKEN(1001, "token异常"),
    FAILED_PARAM(1002, "请求的参数异常"),
    FAILED_SEND(1003, "请求处理中发送请求异常"),
    FAILED_PARAM_DECODE(1004, "请求的参数解码异常"),
    FAILED_PARAM_MAP(1005, "请求的参数映射成Map失败"),
    FAILED_HANDLE(1000, "请求逻辑处理失败"),
    FAILED_WX_MSG(1200, "微信消息发送异常：");

    private Integer code;
    private String msg;
    SendResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 返回请求结果Json
     * @return
     */
    public JsonObject getResultJson(String errorMsg) {
        if (this.code == 1) {
            return new JsonObject().put("result", 1);
        } else {
            return new JsonObject().put("result", 0)
                    .put("errorCode", this.code)
                    .put("errorMsg", this.msg + "[" + errorMsg + "]");
        }
    }

    public static void main(String args[]) {
        System.out.println(SendResult.SUCCESS.getResultJson(null));
    }
}
